package com.lyj.hw_student.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lyj.hw_student.system.entity.Course;
import com.lyj.hw_student.system.entity.StudentCourse;
import com.lyj.hw_student.system.entity.SysRoleMenu;
import com.lyj.hw_student.system.service.ICourseService;
import com.lyj.hw_student.system.service.IStudentCourseService;
import com.lyj.hw_student.system.service.ISysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyj
 * @since 2025-04-22
 */
@RestController
@RequestMapping("/sysRoleMenu")
public class SysRoleMenuController {
    @Autowired
    ISysRoleMenuService sysRoleMenuService;

    /**
     * 添加角色菜单
     * @param sysRoleMenu
     * @return
     */
    @PostMapping("/addRoleMenu")
    public String addRoleMenu(@RequestBody SysRoleMenu sysRoleMenu){
        sysRoleMenuService.save(sysRoleMenu);
        return "ok";
    }

    /**
     * 删除角色菜单
     * @param id
     * @return
     */
    @DeleteMapping("/deleteRoleMenu/{id}")
    public String deleteRoleMenu(@PathVariable Integer id){
        sysRoleMenuService.removeById(id);
        return "ok";
    }

    /**
     * 修改角色菜单
     * @param sysRoleMenu
     * @return
     */
    @PutMapping("/updateRoleMenu")
    public String updateRoleMenu(@RequestBody SysRoleMenu sysRoleMenu) {
        sysRoleMenuService.updateById(sysRoleMenu);
        return "Success";
    }

    /**
     * 查询角色菜单
     * @param roleId
     * @return
     */
    @GetMapping("/selectRoleMenu/{roleId}")
    public List<SysRoleMenu> selectRoleMenu(@PathVariable Integer roleId) {
        // 1. 创建查询条件
        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);

        // 2. 查询该角色关联的所有菜单
        List<SysRoleMenu> roleMenus = sysRoleMenuService.list(queryWrapper);

        return roleMenus;
    }




}
